package com.woniuxy.rbac.controller;

import com.woniuxy.rbac.entity.Role;
import com.woniuxy.rbac.result.ResponseResult;
import com.woniuxy.rbac.service.IRoleService;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: linKe
 * @Date: 2021/11/22 23:40
 * @FileName: RoleController
 * @version: 1.0
 * @Description: 描述
 */
@Log4j2
@RestController
@RequestMapping("/role")
public class RoleController {
    @Resource
    private IRoleService roleService;

    /**
     * 根据动态参数调用
     * @param id  角色id
     * @return  响应对象
     */
    @GetMapping("/{id}")
    public ResponseResult<?> role(@PathVariable int id){
        Role role = roleService.findById(id);
        //打印日志
        log.info(role);
        return new ResponseResult<Role>(200,"查询成功",role);
    }
    /**
     * 根据动态参数调用
     * @return  响应对象
     */
    @GetMapping("/all")
    public List<Role> findAll(){
        List<Role>  role = roleService.findAll();
        //打印日志
        log.info(role);
        return role;
    }
}
